--[[
启动定时器，超时后系统自动调用on_timer
timer_id：定时器ID，0~31
timeout：超时时间，单位毫秒
countdown：0顺计时，1倒计时
repeat：重复次数，0表示无限重复
--]] --
local Timers = {}
--- func desc
---@param timeout any
---@param countdown any
---@param mrepeat any
---@param callback any    定时后的回调函数，传入时钟ID
function simple_start_timer(timeout, countdown, mrepeat, callback)
    local timerId
    for i = 0, 31, 1 do
        if Timers[i] == nil then
            timerId = i
            start_timer(timerId,timeout, countdown, mrepeat)
            Timers[timerId] = callback
            break
        end
    end
    if timerId ~= nil then
        return timerId
    else
        error("no timer")
    end
end

function simple_loop_start_timer(timeout, countdown, callback)
    simple_start_timer(timeout, countdown, 1, callback)
end

function on_timer(timer_id)
    if Timers[timer_id] ~= nil then
        Timers[timer_id](timer_id)
    end
end

function simple_stop_timer(timer_id)
    if Timers[timer_id] ~= nil then
        stop_timer(timer_id)
        Timers[timer_id] = nil
    end
end
